package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.service.ISupplierService;
import com.project.util.InfoResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping("supplier")
@Api(tags = "供应商相关controller")
public class SupplierController {
    @Autowired
    private ISupplierService iSupplierService;

    @GetMapping("showSupplierByPage/{pageNum}/{supplierName}/{supplierScope}")
    private Page<SupplierBean> showSupplierByPage(@PathVariable int pageNum,
                                                  @PathVariable String supplierName,
                                                  @PathVariable String supplierScope) {
        return iSupplierService.showSupplierByPage(pageNum, supplierName, supplierScope);
    }

    @GetMapping("showAllSupplier")
    private List<SupplierBean> showSupplier() {
        return iSupplierService.showAllSupplier();
    }

    @GetMapping("showSupplierById/{supplierId}")
    private SupplierBean showSupplierById(@PathVariable int supplierId) {
        return iSupplierService.showSupplierById(supplierId);
    }

    @PostMapping("addSupplier/{supplierName}/{supplierPeo}/{supplierTel}/{supplierAddress}/{supplierScope}")
    private InfoResult addSupplier(@PathVariable String supplierName,
                                   @PathVariable String supplierPeo,
                                   @PathVariable String supplierTel,
                                   @PathVariable String supplierAddress,
                                   @PathVariable String supplierScope) {
        SupplierBean su = new SupplierBean();
        su.setSupplierAddress(supplierAddress);
        su.setSupplierName(supplierName);
        su.setSupplierPeo(supplierPeo);
        su.setSupplierScope(supplierScope);
        su.setSupplierTel(supplierTel);
        return iSupplierService.addSupplier(su);
    }

    @PostMapping("updateSupplier/{supplierId}/{supplierPeo}/{supplierTel}")
    private InfoResult updateSupplier(@PathVariable int supplierId,
                                      @PathVariable String supplierPeo,
                                      @PathVariable String supplierTel) {
        return iSupplierService.updateSupplier(supplierId, supplierPeo, supplierTel);
    }
}
